<!--
 * @Description:
 * @Version: 0.1
 * @Autor: Civet
 * @Date: 2019-08-02 16:04:58
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2019-10-16 19:19:23
 -->
<template>
  <loginView @sub="sub">
  </loginView>
</template>

<script>
import loginView from './loginView'
import apiHome from "@/httpUtils/apiHome";
export default {

  components: {
    loginView
    // name
  },
  name: "loginLogic",
  props: {
    // msg: String //  [name: typeof]
  },
  filters: {},
  computed: {},
  watch: {},
  data () {
    return {}
  },
  created () {

  },
  mounted () {
    console.log("123", location.href);
  },
  methods: {
    sub (us) {
      if (us.password == '' || us.username == '') {
        this.$message({
          type: 'error',
          message: '用户名或密码不能为空!'
        });
        return;
      }
      // // 假登录
      if (us.password == '123456' && us.username == '13763839260') {
        window.sessionStorage.setItem('userData', JSON.stringify({ "access_token": "ba85fdc5-d861-49e9-a2c8-1c66e67539e3" }))
        this.$router.push('/frame')
      } else {
        this.$message({
          type: 'error',
          message: `账号或密码错误！`
        })
      }

      let newObj = {
        pwd: us.password,
        userName: us.username
      }

      apiHome.login(newObj).then((res) => {
        console.log('登录', res)
        if (res.status == 200) {
          switch (res.data.code) {
            case 9999:
              this.$message({
                type: 'error',
                message: `${res.data.message}！`
              });
              break;
            case 9998:
              this.$message({
                type: 'error',
                message: `${res.data.message}！`
              });
              break;
            case 9997:
              this.$message({
                type: 'error',
                message: `${res.data.message}！`
              });
              break;
            case 0:
              let session = window.sessionStorage;
              let userData = res.data.data;
              session.setItem("userData", userData);
              this.$router.push('/frame');
              break;
          }
        }
      }).catch((err) => {
        console.log('loginerr', err);
      });
    }
  },
  destroyed () {

  }
}
</script>

<style scoped lang="less">
</style>
